﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using NPSoft.Ferrero.DataBridge.Model;
using NPSoft.Ferrero.Framework.DAL;

namespace NPSoft.Ferrero.DataBridge.DAL
{
    public class ProductUOMUtil : IDAL<ProductUOM>
    {
        public int Add(ProductUOM info)
        {
            throw new NotImplementedException();
        }

        public int Edit(ProductUOM info)
        {
            throw new NotImplementedException();
        }

        public ProductUOM GetById(long id)
        {
            throw new NotImplementedException();
        }

        public ProductUOM GetById(Guid id)
        {
            throw new NotImplementedException();
        }

        public int Remove(ProductUOM info)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet Search(StringBuilder condtion)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// SQL连接
        /// </summary>
        private SqlConnection Connection
        {
            get
            {
                return SqlHelper.GetConnection();
            }
        }

        public ICollection<ProductUOM> SearchCollection(StringBuilder condtion)
        {
            ICollection<ProductUOM> infos = new List<ProductUOM>();
            StringBuilder sql = new StringBuilder();
            sql.Append(@"SELECT PRD_CD,UOM_CD,BASEUOM_CD,UOM_LEVEL,CONV_FACTOR,CONV_FACTOR_SML,SML_UOM,SALE_UOM,DEFAULT_UOM,PACK_LENGTH,PACK_WIDTH,PACK_HEIGHT,DIMENSION_UNIT,NET_WEIGHT,GROSS_WEIGHT,WEIGHT_UNIT,VOLUME,EAN_NO	FROM MST_PRDUOM");

            string sWhere = " where ";
            if (!string.IsNullOrEmpty(condtion.ToString()))
            {

                sql.Append(sWhere + condtion);
            }
            DataSet ds;
            ds = SqlHelper.ExecuteDataset(this.Connection, CommandType.Text, sql.ToString());
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                infos.Add(SetInfo(row));
            }
            return infos;
        }

        public ProductUOM SetInfo(System.Data.DataRow row)
        {
            ProductUOM proUOM = new ProductUOM();
            proUOM.PRD_CD = SqlHelper.GetString(row, "PRD_CD");
            proUOM.UOM_CD = SqlHelper.GetString(row, "UOM_CD");
            proUOM.BASEUOM_CD = SqlHelper.GetString(row, "BASEUOM_CD");
            proUOM.UOM_LEVEL = SqlHelper.GetString(row, "UOM_LEVEL");
            proUOM.CONV_FACTOR = SqlHelper.GetString(row, "CONV_FACTOR");
            proUOM.CONV_FACTOR_SML = SqlHelper.GetString(row, "CONV_FACTOR_SML");
            proUOM.SML_UOM = SqlHelper.GetString(row, "SML_UOM");
            proUOM.SALE_UOM = SqlHelper.GetString(row, "SALE_UOM");
            proUOM.DEFAULT_UOM = SqlHelper.GetString(row, "DEFAULT_UOM");
            proUOM.PACK_LENGTH = SqlHelper.GetString(row, "PACK_LENGTH");
            proUOM.PACK_WIDTH = SqlHelper.GetString(row, "PACK_WIDTH");
            proUOM.PACK_HEIGHT = SqlHelper.GetString(row, "PACK_HEIGHT");
            proUOM.DIMENSION_UNIT = SqlHelper.GetString(row, "DIMENSION_UNIT");
            proUOM.NET_WEIGHT = SqlHelper.GetString(row, "NET_WEIGHT");
            proUOM.GROSS_WEIGHT = SqlHelper.GetString(row, "GROSS_WEIGHT");
            proUOM.WEIGHT_UNIT = SqlHelper.GetString(row, "WEIGHT_UNIT");
            proUOM.VOLUME = SqlHelper.GetString(row, "VOLUME");
            proUOM.EAN_NO = SqlHelper.GetString(row, "EAN_NO");

            return proUOM;
        }
    }
}
